import { ElMessage, ElMessageBox } from 'element-plus';
const messageType = [
  {
    type: 'success',
    name: '成功'
  },
  {
    type: 'info',
    name: '提示'
  },
  {
    type: 'warning',
    name: '警告'
  },
  {
    type: 'error',
    name: '错误'
  }
];
/**
 * ## 弹窗提示 ElMessageBox
 * 参数说明
 * type: 消息类型，用于图标显示	四种类型（ success / info / warning / error）
 * title:  MessageBox 的标题
 * message: MessageBox 的正文内容
 * confirmButtonText: 确定按钮的文本内容
 * cancelButtonText:  取消按钮的文本内容
 * setting:其他配置项，对象类型，参见 https://element-plus.gitee.io/zh-CN/component/message-box.html#messagebox-%E9%85%8D%E7%BD%AE%E9%A1%B9
 */
export const biMessageBox = (
  type = 'warning',
  title = '提示',
  message,
  confirmButtonText = '确定',
  cancelButtonText = '取消',
  setting
) => {
  let messageText = '';
  if (!message) {
    messageText = messageType
      .filter((item) => item.type === type)
      .map((e) => e.name)[0];
  } else {
    messageText = message;
  }
  return ElMessageBox.confirm(messageText, title, {
    confirmButtonText,
    cancelButtonText,
    cancelButtonClass: 'cancel-button-class',
    confirmButtonClass: 'confirm-button-class',
    type: type,
    ...setting
  })
    .then(() => {
      return true;
    })
    .catch(() => {
      return false;
    });
};
/**
 * ## 轻提示 ElMessage
 * 参数说明
 * type: 消息类型，用于图标显示	四种类型（ success / info / warning / error）
 * message: MessageBox 的正文内容
 * setting:其他配置项，对象类型，参见 https://element-plus.gitee.io/zh-CN/component/message.html#message-api
 */

export const biMessage = (type = 'success', message, setting = {}) => {
  let messageText = '';
  let customClass = 'success';
  const objs = messageType.filter((item) => item.type === type)[0];
  customClass = objs.type + '-message';
  if (!message) {
    messageText = objs.name;
  } else {
    messageText = message;
  }
  return ElMessage({
    type,
    message: messageText,
    // duration: 0,
    // 'show-close': true,
    'custom-class': customClass,
    ...setting
  });
};
